/**
 * 
 */
package metalink.admin;

import java.util.ArrayList;

import javax.servlet.http.HttpSession;

import myutil.Connect;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import vo.LibraryBookDetailsVo;

/**
 * @author Sony
 * 
 */
public class InsertIntoLibrary extends ActionSupport {
	public String execute() {
		try {
			int count = 0;
			String query = "";
			Connect c = new Connect();
			HttpSession session = ServletActionContext.getRequest().getSession();
			ArrayList<LibraryBookDetailsVo> book_list = (ArrayList<LibraryBookDetailsVo>) session.getAttribute("uploaded_book_list");
			if (book_list != null) {
				for (LibraryBookDetailsVo vo : book_list) {
					for (int i = 0; i < vo.getCount(); i++) {
						query = "insert into library_book_details(book_name,author_name,category,description,price,referred_by,publisher) values('"
								+ vo.getBook_name()
								+ "','"
								+ vo.getAuthor_name()
								+ "','"
								+ vo.getCategory()
								+ "','"
								+ vo.getDescription()
								+ "',"
								+ vo.getPrice()
								+ ",'"
								+ vo.getReferred_by()
								+ "','"
								+ vo.getPublisher() + "')";
						System.out.println(query);
						c.dml(query);
					}
					
					++count;

				}
				addActionError(count + " records are inserted successfully");
				return SUCCESS;
			}

			return ERROR;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return ERROR;
		}
	}
}
